/* 
 * File:   Parallellogram.cpp
 * Author: lgr013
 * 
 * Created on 13 de septiembre de 2014, 12:12
 */

#include "Parallellogram.h"

Parallellogram::Parallellogram() {
}

Parallellogram::Parallellogram(ObjFactory *objFactory, bool flagStatic, float x, float y, float base, float height, double alpha, float mass, float rotation) {
    SBSLog* myLogFile;
    myLogFile->getInstance(MY_LOG_MODE);

    if (height <= 0 || base <= 0){
        myLogFile->writeInLog(2, "[2] Tamaño de paralelogramo invalido\n");                
    }
    
    Dot *dot = new Dot(x,y,base,height);   
    this->dot = dot;

    Object* object = objFactory->getObjectParallellogram(flagStatic, dot->dotPixelsToWorld(), dot->sizeDotPixelsToWorld(), alpha, mass, rotation);
    this->object = object;    
    
    this->alpha = alpha;    // radianes

    myLogFile->writeInLog(0, "[0] Se ha creado un paralelogramo exitosamente\n");                
    
}

Parallellogram::~Parallellogram() {
    delete this->dot;
    delete this->object;
//    printf("destructor Paralelogramo \n");
}

bool Parallellogram::draw(Uint8 r, Uint8 g, Uint8 b, Uint8 a){
    SBSLog* myLogFile;
    myLogFile->getInstance(MY_LOG_MODE);

    bool success = true;
    Object *obj = this->object;

    float posX = obj->getBody()->GetPosition().x;
    float posY = obj->getBody()->GetPosition().y;
    
    this->dot->setPos(posX,posY);

    success = obj->getSkin()->makeParallellogram(this->dot->dotWorldToPixels(), this->dot->sizeDotWorldToPixels(), this->alpha, this->getAngle(),r, g, b, a);

    if (!success){
        myLogFile->writeInLog(2, "[2] Ha ocurrido un error mientras se intentaba dibujar el paralelogramo\n");                    
    }

    return success;
}

b2Vec2 Parallellogram::getPosition(){
    return this->object->getPosition();
}

float Parallellogram::getAngle(){
    return this->object->getAngle();
}

float Parallellogram::getAngularVelocity(){
    return this->object->getAngularVelocity();
}

void Parallellogram::setAngularVelocity(float velocity){
    this->object->setAngularVelocity(velocity);
}
